/*
   PROCEDURES LIST :	
	UPDATE_DOMAIN (p_Nom TEXT, p_champ TEXT, p_value TEXT) RETURNS BOOLEAN
	UPDATE_CONCEPT (p_Nom TEXT, p_champ TEXT, p_value TEXT) RETURNS BOOLEAN
	UPDATE_ASSOCIATION (p_Nom TEXT, p_champ TEXT, p_value TEXT) RETURNS BOOLEAN
*/


/*
*	Function : UPDATE_DOMAIN 
*	Description :
*/

CREATE OR REPLACE FUNCTION UPDATE_DOMAIN (p_Nom TEXT, p_champ TEXT, p_value TEXT) RETURNS BOOLEAN AS $$
BEGIN
	
	IF (p_champ = 'nom') THEN
		UPDATE Domains SET Nom = p_value, DateModif = (SELECT LOCALTIMESTAMP) WHERE Nom = p_Nom;
	ELSE
		IF (p_champ = 'description') THEN
			UPDATE Domains SET Description = p_value, DateModif = (SELECT LOCALTIMESTAMP) WHERE Nom = p_Nom;
		ELSE
			RETURN FALSE;
		END IF;
	END IF;
	
	RETURN TRUE;
END;
$$ LANGUAGE plpgsql;



/*
*	Function : UPDATE_CONCEPT 
*	Description :
*/
CREATE OR REPLACE FUNCTION UPDATE_CONCEPT (p_Nom TEXT, p_champ TEXT, p_value TEXT) RETURNS BOOLEAN AS $$
BEGIN
	IF (p_champ = 'nom') THEN
		UPDATE Concepts SET Nom = p_value, DateModif = (SELECT LOCALTIMESTAMP) WHERE Nom = p_Nom;
	ELSE
		IF (p_champ = 'description') THEN
			UPDATE Concepts SET Description = p_value, DateModif = (SELECT LOCALTIMESTAMP) WHERE Nom = p_Nom;
		ELSE
			RETURN FALSE;
		END IF;
	END IF;
	
	RETURN TRUE;
END;
$$ LANGUAGE plpgsql;


/*
*	Function : UPDATE_ASSOCIATION
*	Description :
*/
/* Trigger pour le miroire */
CREATE OR REPLACE FUNCTION UPDATE_ASSOCIATION (p_Nom TEXT, p_champ TEXT, p_value TEXT) RETURNS BOOLEAN AS $$
BEGIN
	IF (p_champ = 'nom') THEN
		UPDATE Associations SET Nom = p_value WHERE Nom = p_Nom;
	ELSE
		RETURN FALSE;
	END IF;

	RETURN TRUE;
END;
$$ LANGUAGE plpgsql;



